﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MyData.Forms;

namespace MyData.WordAddIn.CustomTaskPanes
{
  /// <summary>
  /// Interaction logic for NotesUserControl.xaml
  /// </summary>
  public partial class NotesUserControl : UserControl
  {
    public Microsoft.Office.Tools.CustomTaskPane HostTaskPane;

    public NotesUserControl()
    {
      InitializeComponent();
    }

    private void notesButton_Click(object sender, RoutedEventArgs e)
    {
      ToolForm form = new ToolForm();
      form.Show(new MyWin32Window(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle));
    }

    private void richTextBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)
    {
      //TODO: Config = 150
      int width = 150;

      richTextBox.ContextMenu.Width = width;

      //HostTaskPane.Control.Width
      if (richTextBox.ViewportWidth < width)
        if (HostTaskPane != null)
        {
          richTextBox.ContextMenu.Width = richTextBox.ViewportWidth;
        }

      if ((richTextBox.ViewportWidth - e.CursorLeft) < richTextBox.ContextMenu.Width)
        if (e.CursorLeft < richTextBox.ContextMenu.Width)
        {
          richTextBox.ContextMenu.HorizontalOffset = richTextBox.ContextMenu.Width - e.CursorLeft;

        }
    }

  }
}
